package com.mybatisx.mybatisplus.enums;

import lombok.Data;

import java.util.Arrays;
import java.util.Optional;

/**
 * @author wuyue
 * @date 2021/9/9 11:13
 */
public enum DbEnum {
    db0(0, "db0(默认master)", -1),
    db1(1, "db1", 0),
    db2(2, "db2", 1);

    /**
     * 用于筛选从库
     *
     * @param slaveNum 从库顺序编号 0开始
     * @return
     */
    public static Optional<DbEnum> getDbTypeBySlaveNum(int slaveNum) {
        return Arrays.stream(DbEnum.values()).filter(b -> b.getSlaveNum() == slaveNum).findFirst();
    }


    DbEnum(int code, String des, int slaveNum) {
        this.code = code;
        this.des = des;
        this.slaveNum = slaveNum;
    }

    private int code;
    private String des;
    private int slaveNum;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getDes() {
        return des;
    }

    public void setDes(String des) {
        this.des = des;
    }

    public int getSlaveNum() {
        return slaveNum;
    }

    public void setSlaveNum(int slaveNum) {
        this.slaveNum = slaveNum;
    }
}

